<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>登录</title>
    <link rel="stylesheet" type="text/css" href="js/jquery-easyui/themes/icon.css">
    <link rel="stylesheet" href="js/jquery-easyui/themes/gray/easyui.css">
    <script src="js/jquery.min.js" type="text/javascript"></script>
    <script src="js/jquery-easyui/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="js/jquery.form.js"></script>
    <script src="js/jquery-easyui/locale/easyui-lang-zh_CN.js"></script>
    <script src="js/md5.js"></script>
    <script src="js/js.cookie.min.js"></script>
</head>
<style type="text/css">

    body {background:url(img/bg.jpg) top center no-repeat; background-size:cover;}

    .panel-title {
        padding: 5px 0;
        text-align: center;
        font-size: 16px;
    }

</style>
<body>
<div class="easyui-window" title="后台管理系统" data-options="modal:false,collapsible:false,minimizable:false,maximizable:false,closable:false,draggable:false,resizable:false,shadow:false" style="width:400px;padding:20px;">
    <form id="form" method="post" data-options="novalidate:true">
        <div style="margin-bottom:10px">
            <input class="easyui-textbox" id="loginid" name="username" style="width:100%;height:40px;padding:12px" data-options="prompt:'登录帐号',iconCls:'icon-man',iconWidth:38">
        </div>

        <div style="margin-bottom:20px">
            <input type="hidden"  name="password" id="md5Pass">
            <input class="easyui-textbox"  id="passwd" type="password" style="width:100%;height:40px;padding:12px" autocomplete="off"  data-options="prompt:'登录密码',showEye:true,iconCls:'icon-lock',iconWidth:38">
        </div>
        <div>
            <a href="javascript:void(0)" class="easyui-linkbutton c6" data-options="iconCls:'icon-ok'" style="padding:5px 0px;width:100%;" onclick="submitForm()">
                <span style="font-size:14px;">登录</span>
            </a>
        </div>
    </form>
</div>
</body>
<script type="text/javascript">
    var login_user=getCookie("login_user");
    var login_pwd=getCookie("login_pwd");
    $(function() {
        $('#loginid').textbox('setValue', login_user);
        $('#passwd').textbox('setValue', login_pwd);
        $('#md5Pass').val(login_pwd);
    });

    function submitForm(){
        $.messager.progress();

        var isValid = $("#form").form('enableValidation').form('validate');
        if (!isValid){
            $.messager.progress('close');
            return false;
        }else{
            if($('#loginid').textbox('getValue')!=login_user){
                var pass = $("#passwd").val();
                $("#md5Pass").val(pass);
                //MD5加密
                //$("#md5Pass").val(md5(pass));
            }
            $.post(
                "/admin/checkLogin",
                $("#form").serialize(),
                function(data) {
                    if (data.code == 1) {
                        location.href = "/home";
                    } else {
                        $.messager.alert('系统提示',"用户名或密码错误",'warning');
                    }
                }, 'json').fail(function(s) {
                $.messager.alert('系统提示','服务器响应失败','error');
            }).always(function() {
                $.messager.progress('close');
            });

        }
    }


    function setCookie(name,value){
        var Days = 7;
        var exp = new Date();
        exp.setTime(exp.getTime() + Days*24*60*60*1000);
        document.cookie = name+"="+ value + ";expires=" + exp.toGMTString();
    }

    function getCookie(name){
        var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
        if(arr=document.cookie.match(reg))
            return unescape(arr[2]);
        else
            return null;
    }
</script>

</html>